package com.ykt.mall.ctrl;

import java.util.HashMap;
import java.util.Map;

import com.jfinal.core.Controller;
import com.jfinal.plugin.activerecord.Model;
import com.ykt.interceptor.Seach;
import com.ykt.mall.content.Content;
import com.ykt.model.Customer;
import com.ykt.model.Shop;

public class BaseWebController<T extends Model<T>> extends Controller {
	
	protected static String tokenName="token";
	protected int tokenTout=600;
	
	public void index(){}
	/**
	 * 得到当前登录会员
	 * @return
	 */
	
	public Customer getLoginCustomer(){
		return getSessionAttr(Content.SESSION_LOGIN_USER);
	}
	public void setLoginCustomer(Customer c){
		setSessionAttr(Content.SESSION_LOGIN_USER,c);
	}
	/**
	 * 得到当前shop
	 * @return
	 */
	public Shop getShop(){
		return getSessionAttr(Content.SESSION_SHOP);
	}
	
	public void filterCustomer(Seach seach){
		seach.setSqlWhere(seach.getSqlWhere()+" and customer_id =?");
		seach.getSqlParam().add(getLoginCustomer().get("id"));
	}
	public void rendJson_(boolean success,String msg,Object... obj){
		Map<String,Object>json=new HashMap<String,Object>();
		json.put("success",success);
		json.put("msg",msg);
		if(obj!=null&&obj.length>0){
			json.put("obj",obj[0]);
		}
		this.renderJson(json);
	}
}
